﻿

<script>
    $(function () {
        //TODO 读写权限控制
        var pageData = {
            EditUser: { SortKey: 0 },
            Mode: "View",
            LanData: $.Languages
        };

        InitPageData();

        //绑定Vue
        var model = new Vue({
            el: "#content",
            data: pageData,
            methods: {
                setPassword: function (event) {
                    //;
                    this.$validate(true);//表单验证

                    if (this.$formValidator.invalid) {
                        $.H3Dialog.Warn({ content: $.Lang("msgGlobalString.FormInvalid") });
                    } else {
                        SetPassword();
                    }
                }
            },
            validators: {
                confirmpwd: function (val) {
                    //;
                    return val == this._vm.EditUser.Password;
                }
            }
        });

        $("#H3ToolBar").AspLinkToolBar();
        $(".H3Panel").BuildPanel({ excludeIDs: ["UserRolelist"] });

        //根据传递的参数获取对应的数据，Vue绑定数据使用
        function InitPageData() {
            var id = getUrlParam("id");
            var mode = getUrlParam("Mode");
            pageData.Mode = mode;
            if (id && id != "") {
                $.ajax({
                    url: $.Controller.OrgUser.GetUserInfo,
                    type: 'get',
                    dataType: "json",
                    data: { unitID: id },
                    async: false,//同步执行
                    success: function (result) {
                        if (result.Extend) {
                            pageData.EditUser = result.Extend;
                        }
                    }
                });
            }
        };

        function SetPassword() {
            //;
            var id = getUrlParam("id");
            //去除前端md5加密，不然会导致重复加密。新添加用户无法登陆。 edit by luoenen
            //var password = $.md5(pageData.EditUser.Password);
            // $.md5(pageData.EditUser.Password);
            var password = pageData.EditUser.Password;
            $.ajax({
                url: $.Controller.OrgUser.SetPassword,
                type: 'post',
                dataType: "json",
                data: { userid: id,password:password },
                async: false,//同步执行
                success: function (result) {
                    if (result.Success) {
                        $.H3Dialog.Success({ content: $.Lang(result.Message) });
                    } else {
                        $.H3Dialog.Warn({ content: result.Message });
                    }
                }
            });
        }
    });
</script>

 <validator name="formValidator">
    <div id="H3ToolBar">
        <a id="lnkOk" href="javscript:void(0)" v-on:click="setPassword" data-icon="fa fa-save" data-lang="GlobalButton.Save"></a>
    </div>
    <div class="H3Panel">
        <span>{{LanData.msgGlobalString.Msg_BasciInfor}}</span>
        <table>
            <tr>
                <td>{{LanData.EditUser.LoginName}}</td>
                <td>
                    <input type="text" disabled="disabled" v-model="EditUser.LoginName" />
                </td>
            </tr>
            <tr>
                <td>
                    {{LanData.EditUser.UserName}}
                </td>
                <td>
                    <input type="text" disabled="disabled" v-model="EditUser.UserName" />
                </td>
            </tr> 
        </table>
    </div>

    <div class="H3Panel">
        <span>{{LanData.Orgnization.OrgInfo}}</span>
        <table>
            <tr>
                <td>{{LanData.EditUser.PasswordNew}}</td>
                <td>
                    <input type="password" id="passwordnew"  v-validate:password="{required:true}" v-model="EditUser.Password" />
                </td>
            </tr>
            <tr>
                <td>
                    {{LanData.EditUser.PasswordNew1}}
                </td>
                <td>
                    <input type="password" id="passwordnew1" v-validate:password1="['confirmpwd']" initial="off" v-model="EditUser.Password2" />
                    <span style="color:Red;" v-if="$formValidator.password1.confirmpwd">{{LanData.EditUser.InvalidPassword}}</span>
                </td>
            </tr>
        </table>
    </div>
</validator>